package com.qin.EducationalManger.student.service.impl;

import java.util.List;

import com.qin.EducationalManger.course.dao.CourseDao;
import com.qin.EducationalManger.student.dao.StudentDao;
import com.qin.EducationalManger.student.model.StudentModel;
import com.qin.EducationalManger.student.service.StudentService;

public class StudentServiceImpl implements StudentService{
	public List<StudentModel> selectAll(StudentModel model) {
		String studentId = model.getStudentId();
		String studentName = model.getStudentName();
 		
		model.setStudentId(studentId);
//		model.setStudentName(studentName);//精确查找
	    model.setStudentName(studentName==null?"%%":"%"+studentName+"%");
	    //如果姓名为空的话 查询全部，如果不为空 模糊查询
		
		
		  List<StudentModel> list = StudentDao.select(model);
		
		
		return list;
}

	@Override
	public int insert(StudentModel model) {
		// TODO Auto-generated method stub
		
		
		return  StudentDao.insert(model);
	}

	@Override
	public Integer delete(StudentModel model) {
		// TODO Auto-generated method stub
		
		return StudentDao.delet(model);
		
	}

	@Override
	public Integer update(StudentModel model) {
		// TODO Auto-generated method stub
		
		return StudentDao.update(model);
		
		
	}
	public Integer updataCourse(String studentId,String courseId) {
		
		StudentModel model  = new StudentModel() ;
		model.setStudentId(studentId);
		List<StudentModel> models = StudentDao.select(model);
		String oldCourseId =models.get(0).getCourseId();
		   System.out.println(oldCourseId);
	
		  
		  String string1 = oldCourseId.replace(courseId, " ");
	
		  
		   String string2  = string1.replace("   ", " ");
	 	
		    System.out.println(string2);
          
			model.setCourseId(string2);
		    
		    
		    return StudentDao.update(model);
		
	}
	

	@Override
	public List<StudentModel> select(StudentModel model) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer selectCount(StudentModel model) {
		// TODO Auto-generated method stub
		return StudentDao.selectCount(model);
	
	}
}
